<template>
	<view class="content">
		<u-toast ref="uToast" />
		<u-modal v-model="modal_show" :content="content"></u-modal>
		
		<view class="top">
			<h2 class="top_h1">西钻远程智能监控平台</h2>
			<!-- <view class="top_title">请登录您所在平台的账号</view> -->
		</view>
		
		
		<view class="box">
			<view class="box_list">
				<view class="icon">
					<u-icon name="account-fill" color="#2979ff" size="50"></u-icon>
				</view>
				<view class="input">
					<u-input v-model="username" placeholder="请输入您的手机号" type="text" :height="100" :border="false"/>
				</view>
			</view>
			<view class="box_list">
				<view class="icon">
					<u-icon name="lock-fill" color="#2979ff" size="50"></u-icon>
				</view>
				<view class="input">
					<u-input v-model="password" placeholder="请输入您的密码" type="password" :height="100" :border="false"/>
				</view>
			</view>
			<button type="default" class="is_ok" @click="login">登录</button>
		</view>
		
			
	</view>
</template>
<script>
export default {
  data() {
    return {
		modal_show:false,//模态框
		content:'',//模态框内容
		username:'',
		password:'',
    };
  },
  methods: {
    login() {
      if (!this.username) {
      	uni.showToast({
      		title: '请输入用户名',
      		icon: 'none'
      	});
      	return;
      }
	  
	  if (!this.password) {
	  	uni.showToast({
	  		title: '请输入密码',
	  		icon: 'none'
	  	});
	  	return;
	  }
	  
	  let data = {
	  	username: this.username,
		password: this.password
	  };
	  
	  this.$base.request(this.$api.Login, 'POST', data).then(res => {
	  		uni.showToast({
	  			title: '登录成功',
	  			duration: 2000,
	  			success: () => {
					uni.setStorageSync('token',res.data.userinfo.token);
					uni.setStorageSync('accessToken',res.data.accessToken);
					uni.setStorageSync('userinfo',res.data.userinfo);
	  				setTimeout(() => {
	  					uni.navigateTo({
	  						url: '/pages/index/index'
	  					});
	  				}, 2000);
	  			}
	  		});
	  }).catch(err => {
	  	uni.showToast({
	  		title: err.msg,
	  		icon: 'none'
	  	});
	  })
    },
  },
};
</script>
<style lang="scss">
@import "./login.scss";
</style>